package mvp.com.bbc.app;

import android.app.Application;
import android.content.Context;
import android.support.compat.BuildConfig;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * Created by Administrator on 2017/9/29.
 */

public class BaseApplication extends Application {
    protected static Context mContext;
    protected static Retrofit mRetrofit;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        //设置网络请求超时时间限制
        builder.connectTimeout(5, TimeUnit.SECONDS);
        mRetrofit = new Retrofit.Builder()
                .client(builder.build())
                .baseUrl(ApiUrls.REQUSTE_HEADE)//添加网络请求头
                //增加返回值为String的支持
                .addConverterFactory(ScalarsConverterFactory.create())
                //增加返回值为Gson的支持(以实体类返回)
                .addConverterFactory(GsonConverterFactory.create())
                //增加返回值为Oservable<T>的支持
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
    }

    public static Retrofit getmRetrofit() {
        return mRetrofit;
    }

    public static Context getmContext() {
        return mContext;
    }
}
